package com.atguigu.gulimall.search.service.impl;

import com.atguigu.gulimall.search.config.ElasticsearchConfig;
import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;


@Service
public class MallSearchServiceImpl implements MallSearchService {

    @Autowired
    private RestHighLevelClient restHighLevelClient;

    @Override
    public SearchResult search(SearchParam searchParam) {
        //1、动态的构建出需要的查询DSL语句
        SearchResult searchResult = null;

        //2：准备检索的请求
        SearchRequest searchRequest = buildSearchRequest();
        //3、执行检索请求
        try {
            SearchResponse search = restHighLevelClient.search(searchRequest, ElasticsearchConfig.COMMON_OPTIONS);
            //4、分析响应数据封装成我们需要的格式
            searchResult = buildSearchResult(search);

        } catch (IOException e) {
            e.printStackTrace();
        }
        return searchResult;
    }

    private SearchResult buildSearchResult(SearchResponse search) {
        return null;
    }

    private SearchRequest buildSearchRequest() {

        return null;
    }
}
